.org 0xF4B00 ; Deploy Ground Units on Cities

Deploy_City:

	PUSH 	{R4, LR}
	
	LDR 	R2, [Deploy_City_1]
	LDR 	R1, [Deploy_City_2]
	LDR 	R3, [R2, 0]
	LDR 	R2, [R1, 0]
	AND		R1, R0, 0xE0
	ADD 	R2, R3, R2, LSL 2		
	LDR 	R2, [R2, 0x48]
	AND		R3, R0, 0x1F
	LDRH 	R0, [R2, 4]
	AND		R1, R1, 0xFF
	AND		R3, R3, 0xFF
	CMP		R1, R0
	LDRH 	R1, [R2, 2]
	
	MOVNE	R0, 0								; Does CO own the Property?
	
	POPNE 	{R4, LR}
	BXNE	LR
	
	CMP		R3, Terrain_City					; Is terrain a City?
	BNE		Terrain_Not_City
	
;-------------------------------------------------------------------------------	
	
	MOV 	R0, 0x98
	MUL 	R4, R1, R0
	ADD 	R0, R2, 0x5000
	LDR 	R0, [R0, 0xA58]
	
	MOV 	R1, CO_City_Deployment				; Skill: City Deployment
	
	ADD 	R0, R0, R4
	ADD 	R0, R0, 0x74
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	BNE		City_Deployment_Attached
	
;-------------------------------------------------------------------------------	

	LDR 	R1, [Deploy_City_1]
	LDR 	R0, [Deploy_City_2]
	LDR 	R1, [R1, 0]
	LDR 	R0, [R0, 0]
	ADD 	R0, R1, R0, LSL 2
	LDR 	R0, [R0, 0x48]		
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]
	ADD 	R1, R0, R4
	LDR 	R0, [R1, 0x6C]
	MOV		R0, R0, LSL 0x14
	MOV		R0, R0, LSR 0x1E
	
	CMP		R0, Power_SCOP						; Has SCOP been activated?
	BNE		No_Deploy_From_City
	
	ADD 	R0, R1, 0x74
	
	MOV 	R1, Rank_Soul_of_Hachi				; Rank: Soul of Hachi
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	BEQ		No_Deploy_From_City
	
;-------------------------------------------------------------------------------	

City_Deployment_Attached:	

	MOV		R0, 1								; You can build units from Cities
	POP 	{R4, LR}
	BX 		LR	
	
;-------------------------------------------------------------------------------	
	
Terrain_Not_City:
	
	LDR		R0, [Deploy_City_3]
	AND		R1, R3, 0x1F
	LDRSB	R0, [R0, R1]
	CMP		R0, 0
	MOVNE	R0, 1								; You can build units from Cities
	POPNE 	{R4, LR}
	BXNE 	LR
	
;-------------------------------------------------------------------------------	

No_Deploy_From_City:
	
	MOV		R0, 0								; You can't build units from Cities	
	POP 	{R4, LR}	
	BX		LR	

;-------------------------------------------------------------------------------		

Deploy_City_1:
	.dw Reg1_Skill
	
Deploy_City_2:
	.dw Reg2_Skill

Deploy_City_3:
	.dw 0x022F4598


